package com.atguigu.gmall.mq.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.common.rabbit.model.GmallCorrelationData;
import com.atguigu.gmall.common.rabbit.util.RabbitService;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.atguigu.gmall.mq.config.DelayedMqConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author: atguigu
 * @create: 2023-06-26 14:55
 */
@RestController
@RequestMapping("/admin/mq")
public class MqController {

    @Autowired
    private RabbitService rabbitService;


    /**
     * 发送普通消息
     *
     * @param msg
     * @return
     */
    @GetMapping("/sendMsg")
    public Result sendMsg(@RequestParam("msg") String msg) {
        String exchange = "exchange.confirm";
        String routingKey = "routing.confirm";
        rabbitService.sendMessage(exchange, routingKey, msg);
        return Result.ok();
    }


    /**
     * 发送普通消息
     *
     * @param msg
     * @return
     */
    @GetMapping("/sendDeadLetterMsg")
    public Result sendDeadLetterMsg(@RequestParam("msg") String msg) {
        String exchange = DeadLetterMqConfig.exchange_dead;
        String routingKey = DeadLetterMqConfig.routing_dead_1;
        rabbitService.sendMessage(exchange, routingKey, msg);
        return Result.ok();
    }


    /**
     * 发送延迟消息-采用延迟插件实现
     *
     * @param msg
     * @param delayTime 延迟时间 单位:s
     * @return
     */
    @GetMapping("/sendDelayMsg")
    public Result sendDelayMsg(@RequestParam("msg") String msg, @RequestParam("delayTime") Integer delayTime) {
        String exchange = DelayedMqConfig.exchange_delay;
        String routingKey = DelayedMqConfig.routing_delay;
        rabbitService.sendDelayMessage(exchange, routingKey, msg, delayTime);
        return Result.ok();
    }

}
